package com.stack.auto_parts.controller;

import com.stack.auto_parts.common.ApiResult;
import com.stack.auto_parts.entity.Orders;
import com.stack.auto_parts.entity.SupplierOrder;
import com.stack.auto_parts.service.SupplierOrderService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @Title: SupplierOrderController
 * @Author WUYU_MIN
 * @Package com.stack.auto_parts.controller
 * @Date 2024/7/9 15:44
 * @description:
 */
@CrossOrigin
@RestController
@RequestMapping("/supplier")
public class SupplierOrderController {

    @Resource
    SupplierOrderService supplierOrderService;

    /**
     *      private String partName;
     *     private Integer number;
     *     private double totalPrice;
     *     private String supplier;
     * @param
     * @return
     */
    @PostMapping("/set")
    public ApiResult<Void> setInfo(@RequestBody SupplierOrder supplierOrder) {
        System.out.println(supplierOrder);
        String string = supplierOrderService.setInfo(supplierOrder);
        if(string  == null)
            return ApiResult.success();
        else
            return ApiResult.fail(string);


    }

    @GetMapping("/list")
    public ApiResult<List<SupplierOrder>> list(){
        return ApiResult.success(supplierOrderService.list());
    }

    @GetMapping("/listByCondition")
    public ApiResult<List<SupplierOrder>> listBycondition(String sipplier, Integer state,Integer commodity_status){
        if(Objects.equals(sipplier, ""))
            sipplier = null;
        if(Objects.equals(state, ""))
            state = null;
        if(Objects.equals(commodity_status, ""))
            commodity_status =null;

        List<SupplierOrder> ordersList = supplierOrderService.selectByCondition(sipplier,state, commodity_status);
        return ApiResult.success(ordersList);
    }
}
